<?php

namespace App\Http\Controllers\Admin\Meeting;

use App\Http\Controllers\Admin\BaseController;
use App\Http\Controllers\Controller;
use App\Models\MeetingService;
use Illuminate\Http\Request;

class ServiceController extends BaseController
{
    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function get(Request $request)
    {
        return ajaxReturn(['service' => MeetingService::find($request->input('id'))]);
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function getAll(Request $request)
    {
        return ajaxReturn(['items' => MeetingService::orderBy('displayorder')->get()]);
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function save(Request $request)
    {
        $service = MeetingService::findOrNew($request->input('id'));
        $service->fill($request->input('service', []))->save();
        return ajaxReturn(['service' => $service]);
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delete(Request $request)
    {
        MeetingService::whereKey($request->input('items', []))->delete();
        return ajaxReturn();
    }
}
